<template>
    <div>
<h1>分类展示页面</h1>

<div v-for="i in cate_list" :key="i.id">
    <p>
        <router-link :to="{path:'/showgoods',query:{'cate_id':i.id}}">
    {{i.name}}
    </router-link>
    <button @click="delcate(i.id)">删除</button>
    <button><router-link :to="{path:'/updatecate',query:{'cate_id':i.id}}">修改</router-link></button>
    </p>
</div>
<p>
        <button @click="up_page">上一页</button>
        <button v-for="i in page_list" :key="i.id" @click="number(i)">{{i}}</button>
        <button @click="down_page">下一页</button>
    </p>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            base_url:'http://127.0.0.1:8000/',
            current_page:1,
            cate_list:[],
            page_list:[],
            page_sum:'',
        }
    },
    methods: {
        delcate(cate_id) {
            let fdata=new FormData()
            fdata.append('cate_id',cate_id)
            axios({
                url:this.base_url+'app01/delcate/',
                method:'delete',
                data:fdata
            }).then(resp=>{
                console.log(resp.data)
                if(resp.data.code==200){
                    alert('删除成功')
                    this.get_cate()
                }
                
            })
            
        },
        down_page() {
            if(this.current_page<this.page_sum){
                this.current_page++
            }
            this.get_cate()
        },
        up_page() {
            if(this.current_page>1){
                this.current_page--
            }
            this.get_cate()
        },
        number(page) {
            this.current_page=page
            this.get_cate()
        },
        get_cate() {
            axios({
                url:this.base_url + 'app01/showcate/',
                method:'get',
                params:{'current_page':this.current_page}
            }).then(resp=>{
                console.log(resp.data)
                this.cate_list=resp.data.data
                this.page_list=resp.data.page_list
                this.page_sum=resp.data.page_sum
            })
        }
    },
    created() {
        this.get_cate()
    }
}
</script>

<style scoped>

</style>
